package com.qpx.jxcupms.web;


import com.alibaba.fastjson.JSON;
import com.qpx.jxc.common.vo.ResultEntity;
import com.qpx.jxcupms.entity.TMenu;
import com.qpx.jxcupms.entity.TUser;
import com.qpx.jxcupms.service.ITMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-22
 */
@RestController
@Controller
@RequestMapping("/upms/menu")
@Slf4j
public class TMenuController {



    @Autowired
    ITMenuService menuService;
    @RequestMapping("/getMenuByUserName")
    public ResultEntity getMenuByUserName(Principal member){
        log.info("當前登錄用戶的信息為:{}", JSON.toJSONString(member));
//        UsernamePasswordAuthenticationToken u = (UsernamePasswordAuthenticationToken) member;
//        //log.info(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        //TODO:admin 死數據
        List<TMenu> menus = menuService.getMenuByUserName(member.getName());
        return ResultEntity.ok(menus);
    }

    public static void main(String[] args) {

        List<TUser> list = new ArrayList<TUser>();
        for (int i = 0;i<100;i++){
            TUser user = new TUser();
            user.setUserName("zhangsan"+i);
            user.setPassword("123456"+i);
            list.add(user);
        }
        String a = JSON.toJSONString(list);
        List<TUser> lists = JSON.parseArray(a, TUser.class);
        System.out.println(lists);
        System.out.println(8>=8-1);

    }

}

